package ah.http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class TestConn {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new TestConn().test();

	}
	public void test() {
		try {
			URL url = new URL("http://api.showji.com/Locating/default.aspx?m=1357578&output=json&jsoncallback=querycallback");
			
			//String params = "message=abccba&1=3";
			URLConnection conn = url.openConnection();
			HttpURLConnection httpConn = (HttpURLConnection)conn;
			httpConn.setDoOutput(true);
			httpConn.setDoInput(true);
			httpConn.setRequestMethod("GET");
			
			PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(httpConn.getOutputStream(), "UTF-8"));
			//printWriter.write(params);
			printWriter.flush();
			printWriter.close();
			
			BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream(), "UTF-8"));
			
			String line = null;
			while ((line=in.readLine())!=null) {
				System.out.println(line);
			}
			for (int i=0; i<999; i++) {
				url = new URL("http://jianghu.taobao.com/u/NjU1NjY4OTI=/front.htmk");
				 conn = url.openConnection();
				 httpConn = (HttpURLConnection)conn;
				httpConn.setDoOutput(true);
				httpConn.setDoInput(true);
				httpConn.setRequestMethod("GET");
				 printWriter = new PrintWriter(new OutputStreamWriter(httpConn.getOutputStream(), "GB2312"));
				//printWriter.write(params);
				printWriter.flush();
				printWriter.close();
				
				 in = new BufferedReader(new InputStreamReader(httpConn.getInputStream(), "GB2312"));
				
				 line = null;
				while ((line=in.readLine())!=null) {
					System.out.println(line);
				}
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
